﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;


namespace WorkingTitleDungeonCrawler
{
    class Map : GameObj
    {
        // Constructor
        public Map(Texture2D dungeongraphics)
        {
            Gfx = dungeongraphics;
            Position = new Vector2(200, 200);
            Angle = 0;
        }


        public int Frame { get; set; }
        const int TileWidth = 48;
        const int TileHeight = 48;
        int[,] Dungeon = new int[20, 20] { {2,1,1,1,1,1,4,0,0,0,0,0,0,0,2,1,4,0,0,0},
                                           {3,7,7,7,7,7,5,0,0,0,0,0,0,0,3,7,5,0,0,0},
                                           {3,7,7,7,7,7,5,0,0,0,0,0,0,0,3,7,5,0,0,0},
                                           {3,7,7,7,7,7,5,0,0,0,0,0,0,0,3,7,5,0,0,0},
                                           {3,7,7,7,7,7,5,0,0,0,0,0,0,0,3,7,5,0,0,0},
                                           {3,7,7,7,7,7,5,0,0,0,0,0,0,2,3,7,5,0,0,0},
                                           {6,6,3,7,5,6,6,0,0,0,0,0,0,3,7,7,5,0,0,0},
                                           {0,0,3,7,5,0,0,0,0,0,0,0,0,3,7,7,5,0,0,0},
                                           {0,0,3,7,5,0,0,0,0,0,0,0,0,3,7,5,6,0,0,0},
                                           {0,0,3,7,5,0,0,0,0,0,0,0,0,3,7,5,1,1,1,4},
                                           {0,0,3,7,5,0,0,0,0,0,0,0,0,3,7,7,7,7,7,5},
                                           {0,0,3,7,5,0,0,0,0,2,1,4,0,3,7,5,6,6,6,6},
                                           {0,0,3,7,5,0,0,0,0,3,7,5,0,3,7,5,0,0,0,0},
                                           {0,0,3,7,5,0,0,0,0,3,7,5,0,3,7,5,0,0,0,0},
                                           {0,0,3,7,5,0,0,0,0,3,7,5,0,3,7,5,0,0,0,0},
                                           {0,0,3,7,5,0,0,0,0,3,7,5,0,3,7,5,0,0,0,0},
                                           {0,0,3,7,5,1,1,1,1,3,7,5,1,3,7,5,0,0,0,0},
                                           {0,0,3,7,7,7,7,7,7,7,7,7,7,7,7,5,0,0,0,0},
                                           {0,0,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,0,0,0},
                                           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

        Vector2 DungeonPosition = new Vector2(0, 0);
        
        
        public override void Draw(SpriteBatch spritebatch, Vector2 DrawOffset)
        {
            

            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    DungeonPosition = new Vector2((float)(j * TileWidth), (float)(i * TileHeight));
                    if (Dungeon[i, j] == 1)
                    {
                        Frame = 1;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                      
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);
                    }
                    else if (Dungeon[i, j] == 2)
                    {
                        Frame = 2;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                      
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);
                    }
                    else if (Dungeon[i, j] == 3)
                    {
                        Frame = 3;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                        
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);
                    }
                    else if (Dungeon[i, j] == 4)
                    {
                        Frame = 4;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                        
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);
                    }
                    else if (Dungeon[i, j] == 5)
                    {
                        Frame = 5;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                        
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);
                    }
                    else if (Dungeon[i, j] == 6)
                    {
                        Frame = 6;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                    
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);
                    }
                    else if (Dungeon[i, j] == 7)
                    {
                        Frame = 7;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                        
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);
                    }
                    else
                    {
                        Frame = 0;
                        Rectangle tmp = new Rectangle((Frame % 1) * 48, Frame * 48, 48, 48);
                      
                        Position = DungeonPosition;
                        spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(400, 300), tmp, Color.White, Angle, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F, SpriteEffects.None, 0);

                    }


                }
            }




           // base.Draw(spritebatch, DrawOffset);
        }
    }
}

